package com.cskaoyan.catmall.service.Impl;

import com.cskaoyan.catmall.dao.LogMapper;
import com.cskaoyan.catmall.model.bo.LogListBo;
import com.cskaoyan.catmall.model.vo.Log.LogListVo;
import com.cskaoyan.catmall.service.LogService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 创建日期: 2022-01-09-09-36
 * author : WQW
 * description: 日志相关的增删改查操作
 */
@Service
public class LogServiceImpl implements LogService {

    @Autowired
    LogMapper logMapper;


    /**
     * @description
     * @author WQW
     * @date 2022/1/10 10:23
     * @param
     * @param logListBo
     * @return com.cskaoyan.catmall.model.vo.Log.LogListVo
     */
    @Override
    public LogListVo getLogList(LogListBo logListBo) {
        Integer page = logListBo.getPage();// 页码
        Integer limit = logListBo.getLimit();// 数据量
        // 通过PageHelper插件，辅助完成分页以及分页信息的获得
        PageHelper.startPage(page, limit);
        List<LogListVo.ListDTO> listDTOS = logMapper.selectAllLog(logListBo);
        PageInfo<LogListVo.ListDTO> pageInfo = new PageInfo<>(listDTOS);
        long total = pageInfo.getTotal();
        int pages = pageInfo.getPages();
        return new LogListVo(total, pages, limit, page, listDTOS);
    }
}
